import { createRouter, createWebHashHistory } from "vue-router"
import Layout from "@/layouts/index.vue"
import home from "./modules/home"
import test from "./modules/test"
import professorManagement from "./modules/professorManagement"
import courseManagement from "./modules/courseManagement"
import channelManagement from "./modules/channelManagement"
import productManagement from "./modules/productManagement"
import marketingManagement from "./modules/marketingManagement"
import customerManagement from "./modules/customerManagement"
import interviewManagement from "./modules/interviewManagement"
import orderManagement from "./modules/orderManagement"
import { Component, markRaw } from "vue"
import type { RouteRecordRaw } from "vue-router"

const routes: RouteRecordRaw[] = [
  {
    path: "/",
    name: "Login",
    component: () => import("@/views/login/index.vue"),
    meta: {
      hidden: true,
      title: "登录",
    },
  },
  ...test,
  ...professorManagement,
  ...channelManagement,
  ...courseManagement,
  ...productManagement,
  ...marketingManagement,
  ...customerManagement,
  ...interviewManagement,
  ...orderManagement,
  ...home,
  // {
  //   path: "/404",
  //   component: () => import("@/views/404.vue"),
  //   meta: { hidden: true, title: "404" },
  // },
  // {
  //   path: "/:pathMatch(.*)*",
  //   redirect: "/404",
  //   meta: { hidden: true },
  // },
]

function markRawWrap(routes: RouteRecordRaw[]) {
  routes.forEach((route) => {
    if (route.meta?.icon && typeof route.meta.icon !== "string") {
      route.meta.icon = markRaw(route.meta.icon)
    }
    if (route.children && route.children.length > 0) {
      markRawWrap(route.children)
    }
  })
  return routes
}

const router = createRouter({
  history: createWebHashHistory(),
  routes: markRawWrap(routes),
})

export default router
